<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

<input type="text" id="i1">
<input type="button" value="平方" onclick="f()">
<div>结果:<span></span></div>

<script>
    function f(){
        let digit = document.querySelector("#i1");
        let d = document.querySelector("span");
        if(isNaN(digit.value)){
            d.innerText = "输入错误";
            return ;
        }

        /*当两个字符串进行*-/运算时会自动转成数值，进行+运算是拼接*/
        /*d.innerText = digit.value*1 + digit.value*1;*/
        /*parseFloat()将字符串转成整数或小数*/
        d.innerText = parseFloat(digit.value) + parseFloat(digit.value);
    }
</script>

</body>
</html>